/*
 * FileContainer.h
 *
 *  Created on: May 1, 2010
 *      Author: Lukasz Spintzyk
 */

#ifndef FILECONTAINER_H_
#define FILECONTAINER_H_


#include "ph.h"
#include "File.h"
class File;
class InodeManager;
class BlockManager;

class FileContainer {
public:
	FileContainer(InodeManager& d_inodeMgr, BlockManager& d_blockMgr);
	~FileContainer();


	uint64_t addFile(const std::string& path, InodePtr inode);
	void removeFileIfExist(const std::string& path);
	bool hasFile(const std::string& path);
	bool hasFile(uint64_t fg);
	FilePtr getFile(const std::string& path);
	FilePtr getFile(uint64_t fh);
	bool renameFile(const std::string& path, const std::string newPath);
	uint64_t getFileHandle(const std::string& path);

	void release(uint64_t fh);

private:
	uint64_t getUniqueFileHandle();

	std::map<uint64_t, FilePtr> d_files;
	std::map<std::string,  uint64_t> d_path2fh;
	InodePtr tab;
	InodeManager& d_inodeMgr;
	BlockManager& d_blockMgr;

	static uint64_t s_file_id;
};

#endif /* FILECONTAINER_H_ */
